home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / menu / menu.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-14  |  9.4 KB  |  285 lines

  1. /* -*- c -*- ------------------------------------------------------------- *
  2.  *
  3.  *   Copyright 2004 Murali Krishnan Ganapathy - All Rights Reserved
  4.  *
  5.  *   This program is free software; you can redistribute it and/or modify
  6.  *   it under the terms of the GNU General Public License as published by
  7.  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  8.  *   Boston MA 02111-1307, USA; either version 2 of the License, or
  9.  *   (at your option) any later version; incorporated herein by reference.
  10.  *
  11.  * ----------------------------------------------------------------------- */
  12.  
  13. /* This program can be compiled for DOS with the OpenWatcom compiler
  14.  * (http://www.openwatcom.org/):
  15.  *
  16.  * wcl -3 -osx -mt <filename>.c
  17.  */
  18.  
  19. #ifndef __MENU_H__
  20. #define __MENU_H__
  21.  
  22. #include "biosio.h"
  23. #include "string.h"
  24.  
  25. // TIMEOUT PARAMETERS
  26. /* If no key is pressed within TIMEOUTNUMSTEPS * TIMEOUTSTEPSIZE milliseconds
  27.    and if a timeout handler is registered, then that will be called.
  28.    The handler should either either take control from there on, or return without
  29.    producing any change in the current video settings.
  30.  
  31.    For e.g. the handler could
  32.    * Could just quit the menu program
  33.    * beep and return.
  34.  
  35.    TIMEOUTSTEPSIZE is the interval for which the program sleeps without checking for 
  36.    any keystroke. So increasing this will make the response of the system slow.
  37.    Decreasing this will make a lot of interrupt calls using up your CPU. Default
  38.    value of TIMEOUTSTEPSIZE of 0.1 seconds should be right in most cases.
  39.  
  40.    TIMEOUTNUMSTEPS of 3000 corresponds to a wait time of 300 seconds or 5 minutes
  41. */
  42.  
  43. #define TIMEOUTSTEPSIZE 10  
  44. #define TIMEOUTNUMSTEPS 30000L
  45.  
  46. // Scancodes of some keys
  47. #define ESCAPE     1
  48. #define ENTERA    28
  49. #define ENTERB   224
  50.  
  51. #define HOMEKEY  71
  52. #define UPARROW  72
  53. #define PAGEUP   73
  54. #define LTARROW  75
  55. #define RTARROW  77
  56. #define ENDKEY   79
  57. #define DNARROW  80
  58. #define PAGEDN   81
  59. #define SPACEKEY 57 // Scan code for SPACE
  60.  
  61. // Attributes
  62. #define NORMALATTR    0x17
  63. #define NORMALHLITE   0x1F // Normal Highlight attribute
  64. #define REVERSEATTR   0x70
  65. #define REVERSEHLITE  0x78 // Reverse Hightlight attribute
  66. #define INACTATTR     0x18
  67. #define INACTHLITE    0x10 // Inactive Highlight attribute
  68. #define REVINACTATTR  0x78
  69. #define REVINACTHLITE 0x70 // Reverse Inactive Highlight attr
  70.  
  71. #define STATUSATTR    0x74
  72. #define STATUSHLITE   0x7B // Status highlight
  73.  
  74. #define FILLCHAR      177
  75. #define FILLATTR      0x01
  76. #define SHADOWATTR    0x00
  77. #define SPACECHAR     ' '
  78.  
  79. #define TFILLCHAR     ' '
  80. #define TITLEATTR     0x70
  81.  
  82. #define ENABLEHLITE   '<' // Char which turns on highlight
  83. #define DISABLEHLITE  '>' // Char which turns off highlight
  84. #define NOHLITE       0   // The offset into attrib array for non-hilite
  85. #define HLITE         1   // The offset for Hlite attrib
  86.  
  87. // Single line Box drawing Chars
  88.  
  89. #define TOPLEFT  218
  90. #define BOTLEFT  192
  91. #define TOPRIGHT 191
  92. #define BOTRIGHT 217
  93. #define TOP      196
  94. #define BOT      196
  95. #define LEFT     179
  96. #define RIGHT    179
  97. #define HORIZ    196
  98. #define LTRT     195 // The |- char
  99. #define RTLT     180 // The -| char
  100.  
  101. // Double line Box Drawing Chars
  102. /*
  103. #define TOPLEFT  201
  104. #define BOTLEFT  200
  105. #define TOPRIGHT 187
  106. #define BOTRIGHT 188
  107. #define TOP      205
  108. #define BOT      205
  109. #define LEFT     186
  110. #define RIGHT    186
  111. #define HORIZ    205
  112. #define LTRT     199 // The ||- char
  113. #define RTLT     182 // The -|| char
  114. */
  115.  
  116. // Attributes of the menu system
  117. #define MAXMENUS      8 // Maximum number of menu's allowed
  118. #define MAXMENUSIZE   12 // Maximum number of entries in each menu
  119.  
  120. // Upper bounds on lengths
  121. // Now that the onus of allocating space is with the user, these numbers
  122. // are only for sanity checks. You may increase these values without
  123. // affecting the memory footprint of this program
  124. #define MENULEN       30 // Each menu entry is atmost MENULEN chars
  125. #define STATLEN       80 // Maximum length of status string
  126. #define ACTIONLEN     80 // Maximum length of an action string
  127.  
  128. // Layout of menu
  129. #define MENUROW       3  // Row where menu is displayed (relative to window)
  130. #define MENUCOL       4  // Col where menu is displayed (relative to window)
  131. #define MENUPAGE      1  // show in display page 1
  132. #define STATLINE      23 // Line number where status line starts (relative to window)
  133.  
  134. // Other Chars
  135. #define SUBMENUCHAR   175 // This is >> symbol
  136. #define RADIOMENUCHAR '>' // > symbol for radio menu? 
  137. #define EXITMENUCHAR  174 // This is << symbol
  138. #define CHECKED       251 // Check mark
  139. #define UNCHECKED     250 // Light bullet
  140. #define RADIOSEL      '.' // Current Radio Selection 
  141. #define RADIOUNSEL    ' ' // Radio option not selected
  142.  
  143. // Types of menu's
  144. #define NORMALMENU 1 
  145. #define RADIOMENU  2
  146.  
  147. typedef enum {OPT_INACTIVE, OPT_SUBMENU, OPT_RUN, OPT_EXITMENU, OPT_CHECKBOX,
  148.           OPT_RADIOMENU, OPT_SEP, OPT_INVISIBLE,
  149.           OPT_RADIOITEM} t_action;
  150.  
  151. typedef union {
  152.   char submenunum; // For submenu's
  153.   char checked; // For check boxes
  154.   char radiomenunum; // Item mapping to a radio menu
  155. } t_itemdata;
  156.  
  157. struct s_menuitem;
  158. struct s_menu;
  159. struct s_menusystem;
  160.  
  161. typedef void (*t_item_handler)(struct s_menusystem *, struct s_menuitem *);
  162. typedef void (*t_menusystem_handler)(struct s_menusystem *, struct s_menuitem *);
  163.  
  164. // TIMEOUT is the list of possible values which can be returned by the handler
  165. // instructing the menusystem what to do. The default is CODE_WAIT
  166. typedef enum {CODE_WAIT, CODE_ENTER, CODE_ESCAPE } TIMEOUTCODE;
  167. typedef TIMEOUTCODE (*t_timeout_handler)(void);
  168.  
  169. typedef struct s_menuitem {
  170.   const char *item;
  171.   const char *status;
  172.   const char *data; // string containing kernel to run.. but... 
  173.   // for radio menu's this is a pointer to the item selected or NULL (initially)
  174.   void * extra_data; // Any other data user can point to
  175.   t_item_handler handler; // Pointer to function of type menufn
  176.   t_action action;
  177.   t_itemdata itemdata; // Data depends on action value
  178.   char shortcut; // one of [A-Za-z0-9] shortcut for this menu item
  179.   char index; // Index within the menu array
  180.   char parindex; // Index of the menu in which this item appears. 
  181. } t_menuitem;
  182.  
  183. typedef t_menuitem *pt_menuitem; // Pointer to type menuitem
  184.  
  185. typedef struct s_menu {
  186.   pt_menuitem items[MAXMENUSIZE];
  187.   const char *title;
  188.   char numitems;
  189.   char numvisible;
  190.   char menuwidth;
  191.   char row,col; // Position where this menu should be displayed
  192. } t_menu;
  193.  
  194. typedef t_menu *pt_menu; // Pointer to type menu
  195.  
  196. typedef struct s_menusystem {
  197.   pt_menu menus[MAXMENUS];
  198.   const char *title; 
  199.   t_menusystem_handler handler; // Handler function called every time a menu is re-printed.
  200.   t_timeout_handler ontimeout; // Timeout handler
  201.   unsigned int tm_stepsize; // Timeout step size (in milliseconds)
  202.   unsigned long tm_numsteps; // Time to wait for key press=numsteps * stepsize milliseconds
  203.  
  204.   char nummenus;
  205.   char normalattr[2]; // [0] is non-hlite attr, [1] is hlite attr
  206.   char reverseattr[2];
  207.   char inactattr[2];
  208.   char revinactattr[2];
  209.   char statusattr[2];
  210.   char fillchar;
  211.   char fillattr;
  212.   char spacechar;
  213.   char tfillchar;
  214.   char titleattr;
  215.   char shadowattr;
  216.   char statline;
  217.   char menupage;
  218.   char maxrow,minrow,numrows; // Number of rows in the window 
  219.   char maxcol,mincol,numcols; // Number of columns in the window
  220. } t_menusystem;
  221.  
  222. typedef t_menusystem *pt_menusystem; // Pointer to type menusystem
  223.  
  224. /************************************************************************
  225.  * IMPORTANT INFORMATION
  226.  *
  227.  * All functions which take a string as argument store the pointer
  228.  * for later use. So if you have alloc'ed a space for the string
  229.  * and are passing it to any of these functions, DO NOT deallocate it.
  230.  *
  231.  * If they are constant strings, you may receive warning from the compiler
  232.  * about "converting from char const * to char *". Ignore these errors.
  233.  *
  234.  * This hack/trick of storing these pointers will help in reducing the size
  235.  * of the internal structures by a lot.
  236.  *
  237.  ***************************************************************************
  238.  */
  239.  
  240. pt_menuitem showmenus(char startmenu);
  241.  
  242. void init_menusystem(const char *title); // This pointer value is stored internally
  243.  
  244. void set_normal_attr(char normal, char selected, char inactivenormal, char inactiveselected);
  245.  
  246. void set_normal_hlite(char normal, char selected, char inactivenormal, char inactiveselected);
  247.  
  248. void set_status_info(char statusattr, char statushlite, char statline);
  249.  
  250. void set_title_info(char tfillchar, char titleattr);
  251.  
  252. void set_misc_info(char fillchar, char fillattr,char spacechar, char shadowattr);
  253.  
  254. void set_window_size(char top, char left, char bot, char right); // Set the window which menusystem should use
  255.  
  256. void reg_handler( t_menusystem_handler handler); // Register handler
  257.  
  258. void unreg_handler(); 
  259.  
  260. void reg_ontimeout(t_timeout_handler, unsigned int numsteps, unsigned int stepsize); 
  261. // Set timeout handler, set 0 for default values.
  262. // So stepsize=0 means numsteps is measured in centiseconds.
  263. void unreg_ontimeout();
  264.  
  265. // Create a new menu and return its position
  266. char add_menu(const char *title); // This pointer value is stored internally
  267.  
  268. void set_menu_pos(char row,char col); // Set the position of this menu.
  269.  
  270. // Add item to the "current" menu // pointer values are stored internally
  271. pt_menuitem add_item(const char *item, const char *status, t_action action, const char *data, char itemdata);
  272.  
  273. void set_shortcut(char shortcut); // Set the shortcut key for the current item
  274.  
  275. // Add a separator to the "current" menu
  276. pt_menuitem add_sep();
  277.  
  278. // Calculate the number of visible items
  279. void calc_visible(pt_menu menu);
  280.  
  281. // Main function for the user's config file
  282. int menumain(char *cmdline);
  283.  
  284. #endif
  285.